package cn.edu.cdu.taobao.servlert;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cdu.api.TaoBaoItemBasicData;
import cn.edu.cdu.api.TaoBaoShopBasicData;
import cn.edu.cdu.api.TmallItemBasicData;
import cn.edu.cdu.taobao.bean.Item;
import cn.edu.cdu.taobao.util.PageInfo;
import cn.edu.cdu.taobao.util.ShopItemInfo;

/**
 * Servlet implementation class ItemInfo
 */
@WebServlet("/ItemInfo")
public class ItemInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ItemInfo() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getRemoteHost();
		String fun = request.getParameter("fun");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html");
		response.setStatus(HttpServletResponse.SC_OK);
		PrintWriter out = response.getWriter();
		System.out.println(fun);
		
		Item item;
		String string=request.getParameter("who");
		
		System.out.println(string);
		
		if (request.getParameter("who").equals("1")) {
			item=TmallItemBasicData.get(fun);
		} else {
			item=TaoBaoItemBasicData.get(fun);
		}
		
		if (item!=null) {
			out.print(item.getItemInfo());
			out.print("<hr>");
			out.print(item.getShopInfo());
			out.print("<hr>");
			out.print(item.getItemPrice());
			out.print("<hr>");
			out.print(item.getItemComment());
			out.print("<hr>");
			out.print(item.getItemTrade());
			
		}
		
		
//		ShopItemInfo shopItemInfo=new ShopItemInfo(fun);
////		System.out.println();
//	out.print(shopItemInfo.getItemInfo());
//	out.print("<hr>");
//	out.print(shopItemInfo.getShopInfo());
//	out.print("<hr>");
//	out.print(shopItemInfo.getPrice());
//	out.print("<hr>");
//	out.print(shopItemInfo.getComment());
//	out.print("<hr>");
//	out.print(shopItemInfo.getTrade());


		
		//out.print(stringBuilder.toString());
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
